/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
 *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
 * };
 */
class Solution {
public:
    int countNodes(TreeNode* root) {

        return getNodesNum(root);

    }

    int getNodesNum(TreeNode* node)
    {
        if (node == nullptr)
            return 0;

        int leftNum = getNodesNum(node->left);
        int rightNum = getNodesNum(node->right);

        int nums = leftNum + rightNum + 1;

        return nums;
    }

};